package com.cdut.controller;

import com.cdut.pojo.Good;
import com.cdut.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@CrossOrigin
@Controller
@RequestMapping("/")
public class ThymeleafController {
    @Autowired
    GoodService goodService;

    @RequestMapping(value = "gridproducts_bannerslider" ,method = RequestMethod.GET)
    public String gridproducts_bannerslider(@RequestParam(defaultValue = "1") int page,Model mv, HttpServletRequest request)
    {
        if(page!=1)
        {
            page= Integer.parseInt(request.getParameter("page"));
        }
        List<Good> goodList = goodService.queryGoodListPage(page, 12);
        mv.addAttribute("goodlist",goodList);
        List<Good> goodList1=goodService.queryGoodList().getData();
        mv.addAttribute("goodlist1",goodList1);
        mv.addAttribute("page",page);
        return "gridproducts_bannerslider";
    }

    @RequestMapping(value="gridproducts_bannerslider_my",method = RequestMethod.GET)
    public String mypage(Model mv,int uid)
    {
        List<Good> goodList=goodService.queryGoodByUid(uid);
        mv.addAttribute("goodlist",goodList);
        return "gridproducts_bannerslider_my";
    }
    @RequestMapping(value = "home" ,method = RequestMethod.GET)
    public String home(Model mv)
    {
        List<Good> goodList=goodService.queryGoodList().getData();
        mv.addAttribute("goodlist",goodList);
        return "home";
    }

    @RequestMapping(value = "productdetails-fullwidth",method = RequestMethod.GET)
    public String productdetailsfullwidth(Model mv,int gid)
    {
        Good good=goodService.queryGoodById(gid).getData();
        mv.addAttribute("good",good);
        return "productdetails-fullwidth";
    }
}
